package com.example.xd.tuiliu_test.videoplayer.render;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.view.TextureView;
import android.view.View;

import com.example.xd.tuiliu_test.videoplayer.render.listener.ISurfaceListener;


public class TextureRenderView extends TextureView implements IRenderView, TextureView.SurfaceTextureListener {
    ISurfaceListener surfaceListener;

    public TextureRenderView(Context context) {
        super(context);
        initView();
    }

    private void initView() {

    }

    @Override
    public ISurfaceListener getISurfaceListener() {
        return surfaceListener;
    }

    @Override
    public void setISurfaceListener(ISurfaceListener surfaceListener) {
        setSurfaceTextureListener(this);
        this.surfaceListener = surfaceListener;
    }

    @Override
    public int getSizeH() {
        return getHeight();
    }

    @Override
    public int getSizeW() {
        return getWidth();
    }

    @Override
    public View getRenderView() {
        return this;
    }

    @Override
    public Bitmap initCover() {
        Bitmap bitmap = Bitmap.createBitmap(
                getSizeW(), getSizeH(), Bitmap.Config.RGB_565);
        return getBitmap(bitmap);
    }

    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        surfaceListener.onSurfaceAvailable(surface, width, height);
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        surfaceListener.onSurfaceSizeChanged(surface, width, height);
    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        return surfaceListener.onSurfaceDestroyed(surface);
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        surfaceListener.onSurfaceUpdated(surface);
    }
}
